import React, { useEffect, useState } from 'react';

import { useLocation } from 'dw-mx-router';
import url from 'url';

// TODO 引入对接万达流程中台的前端组件库
import { WandaUTPDriver } from 'dw-mx-sew-plugin-wanda';

// TODO 引入UTC对应关系的配置文件
import namedutc from '../../config/namedutc';

export default function UTP() {
    // TODO UTP的路由访问入口
    const location = useLocation();
    const para = url.parse(location.search, true);
    const utcName = para.query.utcName;
    const businessToken = para.query.businessToken;
    const groupcode = para.query.groupcode;
    const debugFlag = para.query.debugFlag;

    // 'http://10.72.30.42/api/ggfw-affair-handle/case/queryBusinessToken?businessToken=' + businessToken
    // TODO 此处配置单笔业务信息查询接口地址，即接口文档3.2
    const baseUrl = 'http://10.72.38.158:8180/dw/business/token';

    useEffect(() => {}, []);

    if (!namedutc) {
        throw new Error(`不存在 utcMap 的注册，请检查！`);
    }

    if (!utcName) {
        throw new Error(`缺失参数 utcName ，请检查！`);
    }

    if (!businessToken) {
        throw new Error(`缺失参数 businessToken，请检查！`);
    }

    if (!groupcode) {
        throw new Error(`缺失参数 groupcode，请检查！`);
    }

    if (!baseUrl) {
        throw new Error(`缺失参数 url，请检查！`);
    }

    // @ts-ignore
    return (
        <>
            <WandaUTPDriver utcName={utcName} utcMap={namedutc} businessToken={businessToken} groupcode={groupcode} url={baseUrl} debugFlag={debugFlag} />
        </>
    );
}
